from django.db import models


class SpeedLoanIndustry(models.Model):
    '''行业'''

    name = models.CharField(verbose_name='行业名称', max_length=32)

    class Meta:
        db_table = "tb_speed_loan_industry"
        verbose_name = '行业'
        verbose_name_plural = verbose_name


class SpeedLoanUserInfo(models.Model):
    '''贷款人信息'''

    IS_HOUSE_CHOICES = (
        (0, '否'),
        (1, '是')
    )

    customeruser = models.OneToOneField('users.CustomerUser', verbose_name='用户', on_delete=models.CASCADE)
    mobile = models.CharField(max_length=11, verbose_name='手机号', unique=True)
    realname = models.CharField(max_length=32, verbose_name='客户姓名', null=True, blank=True)
    age = models.IntegerField(verbose_name='年龄')
    province = models.CharField(verbose_name='省', max_length=32)
    city = models.CharField(verbose_name='市', max_length=32)
    district = models.CharField(verbose_name='区/县', max_length=32)
    industry = models.ForeignKey('speeds.SpeedLoanIndustry', verbose_name='行业', on_delete=models.CASCADE)
    address = models.CharField(verbose_name='详细地址', max_length=256)
    business_limit = models.CharField(verbose_name='经营年限', max_length=16)
    is_house = models.SmallIntegerField(verbose_name='是否有固定房产', choices=IS_HOUSE_CHOICES)
    business_no = models.CharField(max_length=32, verbose_name='微邮付商户号', null=True, blank=True)
    level = models.ForeignKey('users.Level', verbose_name='层级', on_delete=models.SET_NULL, null=True, blank=True)
    create_time = models.DateTimeField(verbose_name='添加时间', null=True, blank=True)

    class Meta:
        db_table = "tb_speed_loan_user_info"
        verbose_name = '贷款人信息'
        verbose_name_plural = verbose_name


class SpeedLoanDraw(models.Model):
    '''奖品'''

    PAYMENT_STATUS_CHOICES = (
        (0, '未中奖'),
        (1, '未领取'),
        (2, '已领取'),
        (3, '领取失败'),
        (4, '已撤销'),
        (5, '已过期')
    )

    customeruser = models.OneToOneField('users.CustomerUser', verbose_name='用户', on_delete=models.SET_NULL, null=True, blank=True)
    amount = models.DecimalField(verbose_name='中奖金额', max_digits=10, decimal_places=2, default=0)
    partner_trade_no = models.CharField(verbose_name='商户订单号', max_length=32)
    desc = models.CharField(verbose_name='备注', max_length=100)
    payment_no = models.CharField(verbose_name='支付订单号', max_length=64, null=True, blank=True)
    payment_time = models.DateTimeField(verbose_name='领取时间', null=True, blank=True)
    payment_status = models.SmallIntegerField(verbose_name='领取状态', choices=PAYMENT_STATUS_CHOICES, default=1)
    nonce_str = models.CharField(verbose_name='随机字符串', max_length=32)
    return_msg = models.TextField(null=True, blank=True)
    gears = models.IntegerField(verbose_name='奖项位置')

    class Meta:
        db_table = "tb_speed_loan_draw"
        verbose_name = '奖品'
        verbose_name_plural = verbose_name


class SpeedMerchantAuthDraw(models.Model):
    '''商户认证奖励'''

    PAYMENT_STATUS_CHOICES = (
        (1, '未领取'),
        (2, '已领取'),
        (3, '领取失败')
    )

    PLATFORM_CHOICES = (
        (1, '微邮付'),
        (2, '微邮惠')
    )

    business_no = models.CharField(verbose_name='商户号', max_length=10)
    appid = models.CharField(verbose_name='小程序appid', max_length=32)
    openid = models.CharField(verbose_name='openid', max_length=32, null=True, blank=True)
    amount = models.DecimalField(verbose_name='中奖金额', max_digits=10, decimal_places=2, default=0)
    out_biz_no = models.CharField(verbose_name='订单号', max_length=64, null=True, blank=True)
    partner_trade_no = models.CharField(verbose_name='商户订单号', max_length=32, unique=True)
    desc = models.CharField(verbose_name='备注', max_length=100)
    payment_no = models.CharField(verbose_name='支付订单号', max_length=64, null=True, blank=True)
    payment_time = models.DateTimeField(verbose_name='领取时间', null=True, blank=True)
    payment_status = models.SmallIntegerField(verbose_name='领取状态', choices=PAYMENT_STATUS_CHOICES, default=1)
    nonce_str = models.CharField(verbose_name='随机字符串', max_length=32)
    return_msg = models.TextField(null=True, blank=True)
    platform = models.SmallIntegerField(verbose_name='渠道', choices=PLATFORM_CHOICES, default=1)

    class Meta:
        db_table = "tb_speed_merchant_auth_draw"
        verbose_name = '商户认证奖励'
        verbose_name_plural = verbose_name


class SpeedSendSMS(models.Model):
    '''发送短信'''

    IS_SEND_CHOICES = (
        (0, '未发送'),
        (1, '已发送'),
        (2, '已使用')
    )

    mid = models.CharField(verbose_name='mid', max_length=32, null=True, blank=True)
    identify = models.CharField(verbose_name='identify', max_length=32)
    business_no = models.CharField(verbose_name='business_no', max_length=32)
    mobile = models.CharField(verbose_name='手机', max_length=11)
    content = models.TextField(verbose_name='短信内容', null=True, blank=True)
    add_time = models.DateTimeField(verbose_name='添加时间', auto_now_add=True)
    is_send = models.SmallIntegerField(verbose_name='领取状态', choices=IS_SEND_CHOICES, default=0)

    class Meta:
        db_table = 'tb_speed_send_sms'
        verbose_name = '发送短信'
        verbose_name_plural = verbose_name
